package com.zgkxzx.设计模式.单例;

/**
 * 创建者   zgkxzx
 * 创建日期 2018/5/10.
 * 功能描述 懒汉式
 */
public class SingleInstance3 {

    //private static SingleInstance3 singleInstance; //这里是有同步的DCL问题 volatile

    private static volatile SingleInstance3 singleInstance;

    private SingleInstance3() {

    }

    public synchronized static SingleInstance3 getInstance() {
        if (singleInstance == null)
            synchronized (SingleInstance3.class) {
                if (singleInstance == null)
                    singleInstance = new SingleInstance3();
            }

        return singleInstance;
    }
}
